feat(prompts): chat message placeholders#1222
Merged
Conversation
Contributor
There was a problem hiding this comment.
15 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile
hassiebp
reviewed
Jun 26, 2025
hassiebp
reviewed
Jun 26, 2025
hassiebp
reviewed
Jun 26, 2025
hassiebp
reviewed
Jun 26, 2025
hassiebp
reviewed
Jun 26, 2025
hassiebp
reviewed
Jun 26, 2025
| ) -> None: | ||
| """Backward-compatible setter for raw prompt structure.""" | ||
| for p in prompt: | ||
| if hasattr(p, "type") and hasattr(p, "name") and p.type == "placeholder": |
Contributor
There was a problem hiding this comment.
Using hasattr(p, ...) in the prompt setter may fail for plain dict inputs which lack attribute access. Consider checking if p is a dict (e.g. using 'if isinstance(p, dict) and "type" in p') to support both dicts and objects.
hassiebp
reviewed
Jun 30, 2025
hassiebp
approved these changes
Jun 30, 2025
hassiebp
reviewed
Jun 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Adds support for chat message placeholders in langfuse-python SDK, enabling dynamic templating in prompts with comprehensive test coverage.
ChatMessageWithPlaceholderstype inchat_message_with_placeholders.pyto handle both regular and placeholder messages.create_prompt_request.pyandchat_prompt.pyto useChatMessageWithPlaceholdersfor prompt creation.PlaceholderMessagemodel inplaceholder_message.pyfor template variables.ChatPromptClientinmodel.pyto compile prompts with placeholders, handling unresolved placeholders by logging warnings.get_langchain_prompt()to convert unresolved placeholders toMessagesPlaceholderobjects.test_prompt.pyandtest_prompt_compilation.pyto cover placeholder scenarios, including edge cases and integration with Langchain.This description was created by
for 1c093d2. You can customize this summary. It will automatically update as commits are pushed.
Greptile Summary
Disclaimer: Experimental PR review
Implements chat message placeholder functionality in the langfuse-python SDK, enabling dynamic templating in chat prompts. This feature is critical for scenarios like injecting conversation history or examples into prompts.
ChatMessageWithPlaceholdersunion type inlangfuse/api/resources/prompts/types/chat_message_with_placeholders.pysupporting both regular chat messages and placeholder messagesChatMessageWithPlaceholdersinstead ofChatMessageinlangfuse/api/resources/prompts/types/create_prompt_request.pyPlaceholderMessagePydantic model inlangfuse/api/resources/prompts/types/placeholder_message.pyfor template variablestests/test_prompt.pyfor placeholder scenarios and edge cases